home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap23-demo-carbon events / Drag.h < prev    next >
Text File  |  2001-05-15  |  5KB  |  138 lines

  1. // *******************************************************************************************
  2. // Drag.h                                                                   CARBON EVENT MODEL
  3. // *******************************************************************************************
  4. //
  5. // This program demonstrates drag and drop utilising the Drag Manager.  Support for Undo and
  6. // Redo of drag and drop within the source window is included.
  7. //
  8. // The bulk of the code in the source code file Drag.c is identical to the code in the file
  9. // Text1.c in the demonstration program MonoTextEdit (Chapter 21).
  10. //
  11. // The program utilises the following resources:
  12. //
  13. // •    A 'plst' resource.
  14. //
  15. // •    An 'MBAR' resource, and 'MENU' resources for Apple, File, and Edit menus.
  16. //
  17. // •    A 'WIND' resource (purgeable) (initially visible).
  18. //
  19. // •    'CNTL' resources (purgeable) for the vertical scroll bars in the text editor window and
  20. //        Help dialog, and for the pop-up menu in the Help Dialog.
  21. //
  22. // •    A 'STR#' resource  (purgeable) containing error text strings.
  23. //
  24. // •    A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground, 
  25. //        doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
  26. //
  27. // *******************************************************************************************
  28.  
  29. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
  30.  
  31. #include <Carbon.h>
  32.  
  33. // …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
  34.  
  35. #define rMenubar                    128
  36. #define mAppleApplication    128
  37. #define  iAbout                        1
  38. #define mFile                            129
  39. #define  iNew                            1
  40. #define  iOpen                        2
  41. #define  iClose                        4
  42. #define  iSaveAs                    6
  43. #define  iQuit                        12
  44. #define mEdit                            130
  45. #define  iUndo                        1
  46. #define  iCut                            3
  47. #define  iCopy                        4
  48. #define  iPaste                        5
  49. #define  iClear                        6
  50. #define  iSelectAll                7
  51. #define rWindow                        128
  52. #define rVScrollbar                128
  53. #define rErrorStrings            128
  54. #define  eMenuBar                    1
  55. #define  eWindow                    2
  56. #define  eDocStructure        3
  57. #define  eTextEdit                4
  58. #define  eExceedChara            5
  59. #define  eNoSpaceCut            6
  60. #define  eNoSpacePaste        7
  61. #define  eDragHandler            8
  62. #define  eDrag                        9
  63. #define  eDragUndo                10
  64. #define kMaxTELength            32767
  65. #define kTab                            0x09
  66. #define kBackSpace                0x08
  67. #define kForwardDelete        0x7F
  68. #define kReturn                        0x0D
  69. #define kEscape                        0x1B
  70. #define kReturn                        0x0D
  71. #define topLeft(r)                (((Point *) &(r))[0])
  72. #define botRight(r)                (((Point *) &(r))[1])
  73.  
  74. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… typedefs
  75.  
  76. typedef struct
  77. {
  78.     TEHandle        textEditStrucHdl;
  79.     ControlRef    vScrollbarRef;
  80.     WindowRef        windowRef;
  81.     Boolean            windowTouched;
  82.     Handle            preDragText;
  83.     SInt16            preDragSelStart;
  84.     SInt16            preDragSelEnd;
  85.     SInt16            postDropSelStart;
  86.     SInt16            postDropSelEnd;
  87. } docStructure, *docStructurePointer;
  88.  
  89. // …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
  90.  
  91. void                        main                                        (void);
  92. void                        doPreliminaries                    (void);
  93. OSStatus                appEventHandler                    (EventHandlerCallRef,EventRef,void *);
  94. OSStatus                windowEventHandler            (EventHandlerCallRef,EventRef,void *);
  95. void                        doIdle                                    (void);
  96. void                        doKeyEvent                            (SInt8);
  97. void                      scrollActionFunction        (ControlRef,SInt16);
  98. void                         doInContent                            (Point,EventRecord *,Boolean);
  99. void                        doDrawContent                        (WindowRef);
  100. void                        doActivateDeactivate        (WindowRef,Boolean);
  101. void                        doOSEvent                                (EventRecord *);
  102. WindowRef                doNewDocWindow                    (void);
  103. EventHandlerUPP    doGetHandlerUPP                    (void);
  104. Boolean                    customClickLoop                    (void);
  105. void                        doSetScrollBarValue            (ControlRef,SInt16 *);
  106. void                        doAdjustMenus                        (void);
  107. void                        doMenuChoice                        (MenuID,MenuItemIndex);
  108. void                        doFileMenu                            (MenuItemIndex);
  109. void                        doEditMenu                            (MenuItemIndex);
  110. SInt16                    doGetSelectLength                (TEHandle);
  111. void                        doAdjustScrollbar                (WindowRef);
  112. void                        doAdjustCursor                    (WindowRef);
  113. void                        doCloseWindow                        (WindowRef);
  114. void                        doSaveAsFile                        (TEHandle);
  115. void                        doOpenCommand                        (void);
  116. void                        doOpenFile                            (FSSpec);
  117. void                        doErrorAlert                        (SInt16);
  118. void                      navEventFunction                (NavEventCallbackMessage,NavCBRecPtr,
  119.                                                                                  NavCallBackUserData);
  120.  
  121. OSErr                        doStartDrag                            (EventRecord *,RgnHandle,TEHandle);
  122. OSErr                     dragTrackingHandler            (DragTrackingMessage,WindowRef,void *,DragRef);
  123. SInt16                    doGetOffset                            (Point,TEHandle);
  124. SInt16                  doIsOffsetAtLineStart        (SInt16,TEHandle);
  125. void                        doDrawCaret                            (SInt16,TEHandle);
  126. SInt16                    doGetLine                                (SInt16,TEHandle);
  127.  
  128. OSErr                        dragReceiveHandler            (WindowRef,void *,DragRef);
  129. Boolean                    doIsWhiteSpaceAtOffset    (SInt16,TEHandle);
  130. Boolean                  doIsWhiteSpace                    (char);
  131. char                        doGetCharAtOffset                (SInt16,TEHandle);
  132. SInt16                    doInsertTextAtOffset        (SInt16,Ptr,SInt32,TEHandle);
  133. Boolean                    doSavePreInsertionText    (docStructurePointer);
  134. void                        doUndoRedoDrag                    (WindowRef);
  135.  
  136. // *******************************************************************************************
  137.  
  138.